#@layout()

#define content()

<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'center',border:true">
        <div class="easyui-panel" title="工具栏" style="width:100%;padding:10px;"
             data-options="iconCls:'icon-application_form'">
            开始年份：
            <select name="startDate" id="startDate"></select>&nbsp;&nbsp;
            结束年份：
            <select name="endDate" id="endDate"></select>&nbsp;&nbsp;
            <a href="javascript:;" class="easyui-linkbutton" data-options="plain:true" onclick="searchYearChart();" iconCls="icon-zoom">#(_res.get('system.common.search'))</a>

        </div>
        <br>
        <div class=" easyui-panel" title="统计结果" style="width:100%;padding:10px;"
             data-options="iconCls:'icon-application_form'">
            <div id="regCountCharts"
                 style="height: 400px;border:1px solid #ccc;padding:10px;"></div>
        </div>
    </div>
</div>

#end


#define css()

#end


#define js()

<script type="text/javascript" src="#(ctx)/static/echarts/echarts.min.js"></script>
<script type="text/javascript" src="#(ctx)/static/echarts/macarons.js"></script>

<script type="text/javascript">

    var legendDataArr = new Array();
    legendDataArr.push("#(_res.get('statistic.echarts.auth.sum'))");

    #for(authType : authTypeList)
        legendDataArr.push("#(authType.dictName)");
    #end

    $(function () {
        generateRegStatisticsCharts();

        $("#startDate").combobox({
            url: contextRootPath + '/dataStatistics/getSingleYearList',
            method: 'get',
            valueField: 'year',
            textField: 'year',
            panelHeight: 'auto',
            width:'100px',
            editable: false,
            onChange: function (newValue, oldValue) {
                var endDate = $("#endDate").combobox('getValue');
                if(endDate !== ''&& endDate!=null){
                    if(newValue > endDate){
                        $.messager.alert('警告','开始年份不能大于结束年份','warning');
                        //$(this).combobox('setValue',oldValue);
                    }
                }
            }
        });

        $("#endDate").combobox({
            url: contextRootPath + '/dataStatistics/getSingleYearList',
            method: 'get',
            valueField: 'year',
            textField: 'year',
            panelHeight: 'auto',
            width:'100px',
            editable: false,
            onChange: function (newValue, oldValue) {
                var startDate = $('#startDate').combobox('getValue');
                if(startDate !== '' && startDate !== null){
                    if(newValue < startDate){
                        $.messager.alert('警告','结束年份不能小于开始年份','warning');
                        //$(this).combobox('setValue',oldValue);
                    }
                }
            }
        });
    });

    function searchYearChart(){
        var startDate = $('#startDate').combobox('getValue');
        var endDate = $('#endDate').combobox('getValue');

        if(startDate === '' || startDate === null){
            $.messager.alert('警告','开始年份不能为空','warning');
            return;
        }

        if(endDate === '' || endDate === null){
            $.messager.alert('警告','结束年份不能为空','warning');
            return;
        }
        var starttime = new Date(Date.parse(startDate));
        var endtime = new Date(Date.parse(endDate));

        if(starttime > endtime){
            $.messager.alert('警告','结束年份不能小于开始年份','warning');
            return;
        }
        generateRegStatisticsCharts(startDate,endDate);

    }


    /**
     * 用户注册年度统计
     * @param targetYear
     */
    function generateRegStatisticsCharts(startDate,endDate) {

        var result,staYears;
        var params={};

        if(startDate !== '' && endDate !== ''){
            params.startDate = startDate;
            params.endDate = endDate;
        }

        $.ajax({
            type: 'get',
            url: contextRootPath + "/dataStatistics/getAuthYear",
            data:params,
            async: false,
            dataType: 'json',
            success: function (data) {
                result = data;
            }
        });

        $.ajax({
            type: 'get',
            url: contextRootPath + "/dataStatistics/getStaYears",
            data:params,
            async: false,
            dataType: 'json',
            success: function (data) {
                staYears = data;
            }
        });

        var regCountCharts = echarts.init(document.getElementById("regCountCharts"), 'macarons');
        var option = {
            title: {
                text: "#(_res.get('statistic.echarts.verify.title'))",
                subtext: "#(_res.get('statistic.echarts.verify.main'))"
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                    type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                }
            },
            legend: {
                data: legendDataArr,
                left:'middle'
            },
            toolbox: {
                show: true
            },
            calculable: false,
            xAxis: [
                {
                    type: 'category',
                    data: staYears
                }
            ],
            yAxis: [
                {
                    type: 'value'
                }
            ],
            series: [
                {
                    name: "#(_res.get('statistic.echarts.auth.sum'))",
                    type: 'bar',
                    data: result['#(com.gmrz.uap.datastatistics.DataStatisticsController::STATISTICS_RESULT_KEY_ALL)'],
                    markPoint: {
                        data: [
                            {type: 'max', name: "#(_res.get('statistic.echarts.max'))"},
                            {type: 'min', name: "#(_res.get('statistic.echarts.min'))"}
                        ]
                    },
                    markLine: {
                        lineStyle: {
                            normal: {
                                type: 'dashed'
                            }
                        },
                        data: [
                            {type: 'average', name: "#(_res.get('statistic.echarts.avg'))"}
                        ]
                    }
                },
                #for(authType : authTypeList)
                    {
                        name : "#(authType.dictName)",
                        type : "bar",
                        stack : "#(_res.get('statistic.echarts.reg.sum'))",
                        data : result['#(authType.dictText)']
                    }
                    #if(!for.last)
                        ,
                    #end
                #end
            ]
        };

        regCountCharts.setOption(option);
    }

</script>

#end



